package org.example.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author TonySong
 * @date 2024/6/24 0024
 * @time 11:42
 */
@RestController
@RequestMapping("/test")
public class HelloController {

    @Value("${server.port}")
    private Integer prot;

    @Resource
    private RestTemplate restTemplate;

      @GetMapping("/t1")
      public String test1(){
          //调用A服务？http://localhost:8001/service-a/
          String object = this.restTemplate.getForObject("http://localhost:8001/service-a/", String.class);
          return "hello world"+ this.prot+"获取了"+object;
      }

      @PutMapping("/{id}")
      public String test2(@PathVariable("id") Integer id){
          this.restTemplate.put("http://localhost:8001/service-a/"+id, String.class);
          return "hello world"+ this.prot+"更新了"+id;
      }
}
